import scrapy


class A债卷市场Spider(scrapy.Spider):
    name = "债卷市场"

    start_urls = ["https://www.boc.cn/fimarkets/boud/"]

    def parse(self, response):
        datas = response.xpath("//div[@class='news']/ul[@class='list']/li/a")
        for data in datas:
            href = data.xpath("./@href").get()[1:]
            title = data.xpath("./@alt").get()
            url = f'https://www.boc.cn/fimarkets/boud/{href}'
            headers = {
                'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
                'Accept-Language': 'zh-CN,zh;q=0.9',
                'Cache-Control': 'no-cache',
                'Connection': 'keep-alive',
                'Pragma': 'no-cache',
                'Sec-Fetch-Dest': 'document',
                'Sec-Fetch-Mode': 'navigate',
                'Sec-Fetch-Site': 'none',
                'Sec-Fetch-User': '?1',
                'Upgrade-Insecure-Requests': '1',
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
                'sec-ch-ua': '"Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"',
                'sec-ch-ua-mobile': '?0',
                'sec-ch-ua-platform': '"Windows"',
                'Cookie': 'ariaappid=f0d4a7cfca52bd27ee5dbb3fdd55756e; ariauseGraymode=false',
            }

            yield scrapy.Request(url ,callback=self.parse2,meta={'title':title},headers=headers)
            break
    def parse2(self,response):
        datas = response.xpath("//div[@class='TRS_Editor']/p/text()").extract()
        print(datas)

